package com.beyondsoft.sabg.edu.config;

import com.aliyun.teaopenapi.models.Config;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 析言产品配置类
 */
@Configuration
@Data
public class AnalysisConfig {

    @Value("${analysis.endpoint}")
    private String endpoint;

    @Value("${analysis.workspace-id}")
    private String workspaceId;

    @Value("${analysis.access-key-id}")
    private String accessKeyId;

    @Value("${analysis.access-key-secret}")
    private String accessKeySecret;

    @Value("${analysis.datasource.url}")
    private String datasourceUrl;

    @Value("${analysis.datasource.username}")
    private String datasourceUsername;

    @Value("${analysis.datasource.password}")  
    private String datasourcePassword;

    /**
     * 创建析言客户端
     */
    @Bean
    public com.aliyun.dataanalysisgbi20240823.Client analysisClient() throws Exception {
        // 使用AccessKey和Secret创建凭据
        com.aliyun.credentials.models.Config credentialConfig = new com.aliyun.credentials.models.Config()
                .setAccessKeyId(accessKeyId)
                .setAccessKeySecret(accessKeySecret)
                .setType("access_key");
        
        com.aliyun.credentials.Client credential = new com.aliyun.credentials.Client(credentialConfig);
        
        Config config = new Config()
                .setCredential(credential);
        config.endpoint = endpoint;
        
        return new com.aliyun.dataanalysisgbi20240823.Client(config);
    }
} 